/*
 * @Description:
 * @Author: Haor
 * @Date: 2022-04-02 23:17:34
 * @LastEditTime: 2022-07-30 22:11:20
 * @LastEditors: Haor
 */
import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from "@nestjs/common";
import { UserService } from './user.service'
import { QueryUserByRoleDto } from "@dto/query-user.dto";
import { PagerDto } from "@dto/public.dto";
import { CreateUserDto, UpdateUserDto, ListByDeptDto, QueryListDTO } from "@dto/user.dto";

@Controller('user')
export class UserController {
	constructor(private readonly userService: UserService) {}

	// 创建用户
	@Post()
	create(@Body() createUserDto: CreateUserDto) {
		return this.userService.create(createUserDto)
	}

	// 查询用户
	@Post('/list')
	queryUserList(@Body() data: QueryListDTO) {
		return this.userService.queryUserList(data)
	}

	/**
	 * 根据部门获取用户
	 */
	@Post('/list_by_dept')
	getUserListByDept(@Body() data: ListByDeptDto) {
		return this.userService.getUserListByDept(data)
	}

    /**
     * 根据角色查询用户
     * @param query
     */
	@Get('byRole')
	getUserListByRole(@Query() query: QueryUserByRoleDto) {
	    return this.userService.getUserListByRole(query)
    }

	// 查询指定用户
	@Get(':id')
	findOne(@Param('id') id: string) {
		return this.userService.findOne(+id)
	}

	@Patch(':id')
	update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
		return this.userService.update(+id, updateUserDto)
	}

	@Delete(':id')
	remove(@Param('id') id: string) {
		return this.userService.remove(+id)
	}
}
